# -*- coding: utf-8 -*-
import pymongo
import MySQLdb

class Mysql(object):
    def __init__(self):
        pass

    def execute(self,sqlstr):
        try:
            self.conn = MySQLdb.connect(
                host='175.102.18.112',
                port=3306,
                user='root',
                passwd='new.123',
                db='fx168',
                charset='utf8'
            )
            self.cur = self.conn.cursor()
            self.cur.execute(sqlstr)
        except Exception as e:
            print(e)
        finally:
            # self.cur.close()
            pass


db = pymongo.MongoClient("mongodb://175.102.18.112:27017").fx168.forextime_out

mysql = Mysql()
htmls = db.find()
for html in htmls:
    wordsStr = html["words"]
    sqlStr = "update forextime set url = '"+ html["old_url"] +"', catch_url = 'http://175.102.18.112:5678/?id="+ str(html["_id"]) +"' where id = '"+str(html["_id"])+"';"
    mysql.execute(sqlStr)
    mysql.conn.commit()
mysql.cur.close()

